/* GUI CONVERTED from rerpiq04.p (converter v1.75) Fri Jun 22 15:25:42 2001 */
/* rerpiq04.p - REPETITIVE PART SCHEDULE INQUIRY                              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.9.1.5 $                                                           */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 5.0      LAST MODIFIED: 02/10/89          BY: emb                */
/* REVISION: 5.0      LAST MODIFIED: 04/21/89          BY: emb                */
/* REVISION: 5.0          LAST EDIT: 05/03/89          BY: WUG *B098*         */
/* REVISION: 6.0      LAST MODIFIED: 08/27/90          BY: emb *D040*         */
/* REVISION: 6.0      LAST MODIFIED: 03/28/91          BY: emb *D463*         */
/* REVISION: 7.0      LAST MODIFIED: 02/29/92          BY: smm *F230*         */
/* Revision: 7.3          Last edit: 11/19/92          By: jcd *G345*         */
/* REVISION: 7.3      LAST MODIFIED: 01/21/93          BY: emb *G689*         */
/* REVISION: 7.3      LAST MODIFIED: 04/23/93          BY: emb *GA28*         */
/* REVISION: 7.3      LAST MODIFIED: 03/04/95          BY: ais *G0GD*         */
/* REVISION: 7.3    LAST MODIFIED: 05/16/96 BY: *G1VG* Julie Milligan         */
/* REVISION: 7.4    LAST MODIFIED: 03/18/97 BY: *H0TX* Murli Shastri          */
/* REVISION: 8.6    LAST MODIFIED: 10/22/97            BY: ays *K14B*         */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 03/06/00   BY: *M0KH* J. Fernando        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 05/12/00   BY: *N09X* Antony Babu        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.9.1.5 $    BY: Hualin Zhong   DATE: 06/13/01 ECO: *N0ZF*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rerpiq04_p_3 "View"
/* MaxLen: Comment: */

&SCOPED-DEFINE rerpiq04_p_5 "Weekday"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable mode as character format "x(10)" label {&rerpiq04_p_3}.
define variable mode_values as character extent 3.
define variable mode_nbr as integer initial 1.
define variable site like rps_site.
define variable due like rps_due_date.
define variable due2 like rps_due_date.
define variable start_date as date.
define variable part like rps_part.
define variable open_ref as integer extent 8 format "->>>>>9".
define variable tot_open as integer extent 8 format "->>>>>9".
define variable wday as character format "x(9)" label {&rerpiq04_p_5}.
define variable wdays as character extent 8 format "x(7)".
define variable i as integer.
define variable frame_title as character format "x(40)".
define variable open_temp like rps_qty_req.
define variable prline like rps_line.
define variable rps_start like rps_due_date.
define variable scheduled like mfc_logical extent 7 no-undo.
define variable ii as integer.

assign
   mode_values[1] = getTermLabel("SCHEDULED",10)
   mode_values[2] = getTermLabel("OPEN",10)
   mode_values[3] = getTermLabel("COMPLETE",10)
   wdays[1]       = "  " + getTermLabelRt("MONDAY",5)
   wdays[2]       = "  " + getTermLabelRt("TUESDAY",5)
   wdays[3]       = "  " + getTermLabelRt("WEDNESDAY",5)
   wdays[4]       = "  " + getTermLabelRt("THURSDAY",5)
   wdays[5]       = "  " + getTermLabelRt("FRIDAY",5)
   wdays[6]       = "  " + getTermLabelRt("SATURDAY",5)
   wdays[7]       = "  " + getTermLabelRt("SUNDAY",5)
   wdays[8]       = "  " + getTermLabelRt("TOTAL",5)
   part           = global_part
   site           = global_site
   due            = today.

find first lnd_det no-lock
where lnd_site = site
  and lnd_part = part no-error.
if available lnd_det then prline = lnd_line.

find first rpc_ctrl no-lock no-error.
if available rpc_ctrl then do:
   rps_start = today.
   if rpc_wk_start < 8 then do:
      if rpc_wk_start = 0 then
         rps_start = rps_start - rpc_sch_bck.
      else do:
         if weekday(today) >= rpc_wk_start then
            rps_start = rps_start
                      - weekday(rps_start) + rpc_wk_start.
         else
            rps_start = rps_start
                      - weekday(rps_start) + rpc_wk_start - 7.
      end.
   end.
end.

/* New Selection Form */


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   part site prline due mode no-attr-space
with frame a no-underline width 80 attr-space THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

mode = mode_values[mode_nbr].

{wbrp01.i}
repeat:

   if c-application-mode <> 'web' then
      update
         part
         site
         prline
         due
         mode
      with frame a editing:

      if frame-field = "part" then do:
         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp.i rps_mstr part rps_part part rps_part rps_part}
         if recno <> ? then do:
            display
               rps_part @ part with frame a.
            find pt_mstr no-lock where pt_part = rps_part no-error.
            if available pt_mstr then
            recno = ?.
         end.
      end.
      else if frame-field = "site" then do:
         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp05.i rps_mstr rps_part
            "rps_part = input part" rps_site "input site"}
         if recno <> ? then do:
            display
               rps_site @ site with frame a.
            recno = ?.
         end.
      end.
      /* Add Line */
      else if frame-field = "prline" then do:
         /*FIND NEXT/PREVIOUS RECORD */
         {mfnp05.i rps_mstr rps_part
            "rps_site = input site and rps_part = input part"
            rps_line "input prline"}
         if recno <> ? then
            display
               rps_line @ prline with frame a.
         recno = ?.
      end.
      else if frame-field = "mode" then do:
         status input stline[1].
         readkey.
         if lastkey = 32
            or keyfunction(lastkey) = "cursor-down"
            or keyfunction(lastkey) = "page-down"
            or keyfunction(lastkey) = "delete-line"
            or keylabel(lastkey) = "F10" then do:
            mode_nbr = max(1,(mode_nbr + 1) modulo 4).
            display
               mode_values[mode_nbr] @ mode with frame a.
         end.
         else
         if keyfunction(lastkey) = "cursor-up"
            or keyfunction(lastkey) = "page-up"
            or keyfunction(lastkey) = "new-line"
            or keylabel(lastkey) = "F9" then do:
            mode_nbr = mode_nbr - 1.
            if mode_nbr = 0 then
               mode_nbr = 3.
            display
               mode_values[mode_nbr] @ mode with frame a.
         end.
         else do:
            apply lastkey.
            do i = 1 to 3:
               do ii = length(input mode) to 1 by -1:
                  if index(mode_values[i],substring(input mode,1,ii)) = 1
                  then do:
                     assign
                        mode = mode_values[i]
                        mode_nbr = i.
                     display
                        mode with frame a.
                     leave.
                  end.
               end.
            end.
         end.
      end.
      else do:
         status input.
         readkey.
         apply lastkey.
      end.
   end.

   {wbrp06.i &command = update
             &fields = "  part site  prline due  mode "
             &frm = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web' and
      (c-web-request begins 'data')) then do:

      find pt_mstr no-lock where pt_part = part no-error.
      if not available pt_mstr then do:

         /* ITEM NUMBER DOES NOT EXIST */
         {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
         if c-application-mode = 'web' then
            return.
         undo, retry.
      end.

      display
         pt_part @ part with frame a.

      find si_mstr no-lock where si_site = site no-error.
      if not available si_mstr then do with frame a:

         /* SITE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}

         if c-application-mode = 'web' then
            return.
         else
            next-prompt site.
         undo, retry.
      end.

      find first ln_mstr no-lock where ln_line = prline no-error.
      if not available ln_mstr and prline > "" then do:

         /* PRODUCTION LINE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=8524 &ERRORLEVEL=3}

         if c-application-mode = 'web' then
            return.
         else
            next-prompt prline with frame a.
         undo, retry.
      end.

      find first ln_mstr no-lock
      where ln_line = prline
        and ln_site = site no-error.
      if not available ln_mstr then do:
         find first ln_mstr no-lock where ln_site = site no-error.
         if available ln_mstr then do:

            /* SITE PRODUCTION LINE DOES NOT EXIST */
            {pxmsg.i &MSGNUM=8526 &ERRORLEVEL=3}

            if c-application-mode = 'web' then
               return.
            else
               next-prompt prline with frame a.
            undo, retry.
         end.
      end.

      find first rps_mstr no-lock
      where rps_part = part
        and rps_site = site
        and rps_line = prline
        no-error.
      if not available rps_mstr then do:

         /* ITEM NOT DEFINED ON THIS PRODUCTION LINE */
         {pxmsg.i &MSGNUM=8527 &ERRORLEVEL=3}
         if c-application-mode = 'web' then
            return.
         undo,retry.
      end.

      check-mode:
      do:
         do i = 1 to 3:
            if mode = mode_values[i] then do:
               mode_nbr = i.
               display
                  mode with frame a.
               leave check-mode.
            end.
         end.

         /* MESSAGE CONSTRUCT HAS BEEN SHIFTED ABOVE THE WEB CONSTRUCT SO */
         /* THAT IT WILL BE DISPLAYED IN NETUI ENVIRONMENT.               */

         /* NOT A VALID CHOICE */
         {pxmsg.i &MSGNUM=13 &ERRORLEVEL=3}
         {pxmsg.i &MSGTEXT = "mode_values[1] + "" - ""
                           + mode_values[2] + "" - "" + mode_values[3]"}

         if c-application-mode = 'web' then return.
         else next-prompt mode with frame a.

         undo, retry.
      end.

      hide frame b.

   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "terminal"
               &printWidth = 80
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "no"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}

   /* FIND AND DISPLAY */
   find first rps_mstr no-lock
   where rps_part = part
     and rps_site = site
     and rps_line = prline
     and (rps_due_date >= due or due = ?) no-error.

   if available rps_mstr then do:

      if due = ? then
         start_date = rps_due_date.
      else
         start_date = due.
      if weekday(start_date) = 1 then
         start_date = start_date - 6.
      else
         start_date = start_date + 2 - weekday(start_date).

      if mode_nbr = 1 then
         frame_title = getFrameTitle("QUANTITY_SCHEDULED",19).
      else
      if mode_nbr = 2 then
         frame_title = getFrameTitle("QUANTITY_OPEN",18).
      else
      if mode_nbr = 3 then
         frame_title =  getFrameTitle("QUANTITY_COMPLETED",19).

      tot_open = 0.

      repeat with frame b down:

         
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


         FORM /*GUI*/  header
            getTermLabel("WEEK_OF",13) + " "
            wdays[1 for 7]
            space(6)
            wdays[8]
            skip
         with STREAM-IO /*GUI*/  frame b width 80 title color normal frame_title.

         assign
            open_ref  = 0
            scheduled = no.

         do i = 1 to 7:
            find rps_mstr
            where rps_part = part
              and rps_site = site
              and rps_line = prline
              and rps_due_date = start_date + i - 1 no-lock no-error.
            if available rps_mstr and (due <= rps_due_date or due = ?) then do:

               if mode_nbr = 1 then
                  open_ref[i] = rps_qty_req.
               else
               if mode_nbr = 2 then do:
                  find mfc_ctrl
                  where mfc_field = "rpc_using_new"
                  no-lock no-error.

                  if (available mfc_ctrl
                     and not mfc_logical       /* Std Repetitive*/
                     and rps_due_date >= rps_start)
                     or (available mfc_ctrl
                     and mfc_logical)          /* Adv Repititive*/
                     or not available mfc_ctrl then
                     open_ref[i] = rps_qty_req - rps_qty_comp.
                  else
                     next.
               end.

               else
               if mode_nbr = 3 then
                  open_ref[i] = rps_qty_comp.
               assign
                  open_ref[8]  = open_ref[8] + open_ref[i]
                  scheduled[i] = yes.
            end.
         end.

         if mode_nbr = 2 then do:
            assign
               open_ref[8] = max(open_ref[8],0)
               open_temp   = 0.
            do i = 7 to 1 by -1:
               assign
                  open_ref[i] = open_ref[i] + open_temp
                  open_temp   = 0.
               if open_ref[i] < 0 then
                  assign
                     open_temp   = open_ref[i]
                     open_ref[i] = 0.
            end.
            if open_temp < 0 then
               do i = 1 to 7:
                  assign
                     open_ref[i] = open_ref[i] + open_temp
                     open_temp = 0.
                  if open_ref[i] < 0 then
                     assign
                        open_temp = open_ref[i].
                        open_ref[i] = 0.
               end.
         end.

         do i = 1 to 7:
            assign
               tot_open[i] = tot_open[i] + open_ref[i]
               tot_open[8] = tot_open[8] + open_ref[i].
         end.

         display
            start_date
            open_ref[1] when (scheduled[1] or open_ref[1] <> 0)
            open_ref[2] when (scheduled[2] or open_ref[2] <> 0)
            open_ref[3] when (scheduled[3] or open_ref[3] <> 0)
            open_ref[4] when (scheduled[4] or open_ref[4] <> 0)
            open_ref[5] when (scheduled[5] or open_ref[5] <> 0)
            open_ref[6] when (scheduled[6] or open_ref[6] <> 0)
            open_ref[7] when (scheduled[7] or open_ref[7] <> 0)
         with frame b width 80 no-attr-space no-labels STREAM-IO /*GUI*/ .

         if scheduled[1] or scheduled[2] or scheduled[3]
            or scheduled[4] or scheduled[5] or scheduled[6]
            or scheduled[7] then
            display
               open_ref[8] format "->>>,>>>,>>9"
            with frame b width 80 no-attr-space no-labels STREAM-IO /*GUI*/ .

         start_date = start_date + 7.

         find first rps_mstr
         where rps_part = part
           and rps_site = site
           and rps_line = prline
           and rps_due_date >= start_date no-lock no-error.
         if available rps_mstr then
            next.

         down 1 with frame b.

         display
            getTermLabel("TOTAL",8) @ start_date
            tot_open[1] @ open_ref[1]
            tot_open[2] @ open_ref[2]
            tot_open[3] @ open_ref[3]
            tot_open[4] @ open_ref[4]
            tot_open[5] @ open_ref[5]
            tot_open[6] @ open_ref[6]
            tot_open[7] @ open_ref[7]
            tot_open[8] @ open_ref[8]
         with frame b STREAM-IO /*GUI*/ .
         leave.
      end.
   end.
   {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


   /* LIST COMPLETE */
   {pxmsg.i &MSGNUM=8 &ERRORLEVEL=1}
end.

assign
   global_part = part
   global_site = site.

{wbrp04.i &frame-spec = a}
